import Vue from 'vue/dist/vue.js'
import App from './App.vue'
import VueRouter from 'vue-router'
import VueResource from 'vue-resource'
import Element from 'element-ui'
import 'element-ui/lib/theme-default/index.css';
import routerList from './routers.js'
import * as Cookie from './plug/cookie.js'
import * as Load from './plug/load.js'

const router = new VueRouter( routerList.lists() )
window.$ = window.jQuery = require('jquery');
require('./plug/jquery.page.js')
Vue.use(VueRouter)
Vue.use(VueResource)
Vue.use(Element)
Vue.prototype.cookie = Cookie
Vue.prototype.load = Load
require('./plug/ueditor/ueditor.config.js');
require('./plug/ueditor/ueditor.all.js');
//路由拦截
Vue.http.interceptors.push((request, next) => {
//   var data=Cookie.getCookie('token');
//   var token='';
//   if(data!==false){
//     token==data;
//   }
// //传送head头 验证cookie是否正确
//   request.headers.set('X-CSRF-TOKEN',token);
  next()
});

//验证用户是否登陆
router.beforeEach((to, from, next) => {
//   var data=Cookie.getCookie('token');
// //如果cookie存在 就回到home页面
//   if(data!==false&&to.path=='/login'){
//     router.replace('home');
//   }
//   //验证本地是否存在cookie
//   if(data===false&&to.path!=='/login'){
//     router.replace('login');
//   }
//   //验证服务器token
//   if(data!==false&&to.path!=='/login'){
//     Vue.http.post('/admin/login/check',{token:data}).then(function(response){
//         if(!response.data.status){
//           router.replace('login');
//         }
//       },function(response){
//           router.replace('login');
//       }).bind(this);
//   }
  next();
})

new Vue(Vue.util.extend({ router }, App)).$mount('#app')